﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ARSoft.Tools.Net.Dns;

namespace simpleDns
{
    public partial class recRecordConfig : Form
    {
        public ARECORD rcd;
        public void init()
        {
            InitializeComponent();
            foreach(string s in Enum.GetNames(typeof(RecordType)))
            {
                tbType.Items.Add(s);
            }
        }
        public recRecordConfig()
        {
            init();
            rcd = new ARECORD();
            this.Text = "新建解析记录";
            rcd.enable = true;
        }
        public recRecordConfig(ARECORD ar)
        {
            init();
            rcd = ar;
            this.Text = "编辑解析记录";
            tbType.Text = ar.type.ToString();
            tbInfo.Text = ar.info;
            tbName.Text = ar.name;
            rbEnable1.Checked = ar.enable;
            rbEnable2.Checked = !ar.enable;
            tbValue.Text = ar.value;
        }

        private void tbSave_Click(object sender, EventArgs e)
        {
            if(string.IsNullOrEmpty(tbName.Text.Trim()) || string.IsNullOrEmpty(tbValue.Text.Trim()))
            {
                MessageBox.Show("前缀和值是必填");
                return;      
            }
            this.DialogResult = DialogResult.OK;
        }

        private void tbCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }

        private void btType_SelectedIndexChanged(object sender, EventArgs e)
        {
            rcd.type =(RecordType) Enum.Parse(typeof(RecordType), tbType.Text,true);
        }

        private void tbName_TextChanged(object sender, EventArgs e)
        {
            rcd.name = tbName.Text.Trim();
        }

        private void tbValue_TextChanged(object sender, EventArgs e)
        {
            rcd.value = tbValue.Text.Trim();
        }

        private void tbInfo_TextChanged(object sender, EventArgs e)
        {
            rcd.info = tbInfo.Text.Trim();
        }

        private void rbEnable1_CheckedChanged(object sender, EventArgs e)
        {
            rcd.enable = rbEnable1.Checked;
        }

        private void rbEnable2_CheckedChanged(object sender, EventArgs e)
        {
            rcd.enable = !rbEnable2.Checked;
        }
    }
}
